'use strict';

let baseService =require('./baseService.js');

class goodsCateService extends baseService {
   async list() {
        const {service,model} = this.ctx;

        let listResult=await model.GoodsCate.aggregate([

           {
               $lookup:{
                   from:'goods_cate',
                   localField:'_id',
                   foreignField:'pid',
                   as:'items'
               }
           },
           {
               $match:{
                   "pid":'0'
               }
           }

       ])


       return listResult
    }
    async doAdd(bodyData) {
        const {service,model} = this.ctx;
        let res=new model.GoodsCate(bodyData)
        let addResult=await res.save();

        return addResult
    }
    async doEdit(editId) {
        const {service,model} = this.ctx;
        let editResult=await model.GoodsCate.find({"_id":editId});
        
        return editResult
    }
    async findById(findId) {
        const {service,model} = this.ctx;
        let findResult=await model.GoodsCate.find({"_id":findId});

        return findResult
    } 
}

module.exports =goodsCateService;

